<template>
  <div>
    <el-form
      :model="ruleForm"
      status-icon
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
    <el-row>
        <el-col>
            <el-form-item label="用户名" prop="uname"
        >
        </el-form-item>
        </el-col>
        <el-col>
            <el-input v-model="ruleForm.uname"></el-input>
        </el-col>
    </el-row>
     <el-row>
        <el-col>
            <el-form-item label="密码" prop="password"
        >
        </el-form-item>
        </el-col>
        <el-col>
            <el-input v-model="ruleForm.password"></el-input>
        </el-col>
    </el-row>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')"
          >登录</el-button
        >
        <el-button @click="regiter">注册</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        uname: "",
        password: "",
      },
      rules: {
        uname: [{ required: true, message: "请输入用户名", trigger: "blur" }],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$axios
            .post(
              "http://localhost:55943/api/Login?uname=" +
                this.ruleForm.uname +
                "&password=" +
                this.ruleForm.password +
                ""
            )
            .then((res) => {
              if (res.data.code > 0) {
                this.$message.success("登录成功");
                this.$router.push("/pageFirst");
                localStorage.setItem("id",res.data.data.UId);
               
              } else {
                this.$message.error("登录失败");
              }
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    regiter() {
      this.$router.push("/register");
    },
  },
};
</script>

<style>

</style>